import pymysql

host="localhost"
port=3306
user="root"
password="root"
database="finance"

# 专门处理增，删，改
def update(sql,param):
    con = pymysql.connect(host=host,port=port,user=user,password=password,database=database)
    cursor =  con.cursor()
    cursor.execute(sql,param)
    con.commit()
    cursor.close()
    con.close()

# 专门处理查询
def  select(sql,param):

    con = pymysql.connect(host=host,port=port,user=user,password=password,database=database)
    cursor =  con.cursor()
    cursor.execute(sql,param)
    data =  cursor.fetchall()
    con.commit()
    cursor.close()
    con.close()
    return data


if __name__=="__main__":
    sql = "select * from user where username  = %s"
    param = ["lisi2"]
    print(select(sql,param))
    print(len(select(sql,param)))